package com.github.tetrisgame.ui.activity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AnimationSet;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.github.tetrisgame.R;
import com.github.tetrisgame.base.BaseActivity;
import com.github.tetrisgame.databinding.ActivityAdvertisementBinding;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

public class AdvertisementActivity extends AppCompatActivity {
    Timer timer = new Timer();
    ActivityAdvertisementBinding activityAdvertisementBinding;
    private int time = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        activityAdvertisementBinding = ActivityAdvertisementBinding.inflate(getLayoutInflater());
        setContentView(activityAdvertisementBinding.getRoot());
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        initEvent();

        activityAdvertisementBinding.circleProgressBar.setTotalTime(360);
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                if(time <= 360){
                    time++;
                }
                runOnUiThread(()->{
                        if(time<=360){
                            activityAdvertisementBinding.circleProgressBar.setTime(time);
                            activityAdvertisementBinding.circleProgressBar.invalidate();
                        }else{

                            changePage();


                        }
                });
            }
        };
        timer.schedule(timerTask,0,17);


    }
    private void changePage(){
        Intent intent = new Intent(AdvertisementActivity.this,LoginActivity.class);
        startActivity(intent);
    }
    private void initEvent(){
        activityAdvertisementBinding.circleProgressBar.setOnClickListener(v -> {
            timer.cancel();
            timer = null;
            changePage();
        });
    }
}
